#include	<string.h>
#include	"server.h"

static void	start_server(t_fdc *fdc)
{
  fd_set	fd_read;
  int		fd_max;
  int		i;

  while (42)
  {
    FD_ZERO(&fd_read);
    fd_max = 0;
    for (i = 0; i < MAX_FD; i++)
      if (fdc->fd_type[i] != FD_FREE)
	{
	FD_SET(i, &fd_read);
	fd_max = i;
      }
    xselect(fd_max + 1, &fd_read, NULL, NULL, NULL);
    for (i = 0; i < MAX_FD; i++)
      if (FD_ISSET(i, &fd_read))
	fdc->fct_read[i](fdc, i);
  }
}

int		main(int ac, char **av)
{
  t_fdc		fdc;

  if (ac != 2)
  {
    printf("%s : ./serveur [port]\n", av[0]);
    return (0);
  }
  fdc.port = atoi(av[1]);
  memset(fdc.fd_type, FD_FREE, MAX_FD);
  init_server(&fdc);
  start_server(&fdc);
  return (0);
}
